<template>
  <view class="normal-login-container">

    <view class="item-wrap" style="margin-bottom: 0">
      <view class="lineBottom10">
        <uni-section title="车辆信息" type="line"/>
      </view>

      <view style="margin: 8rpx 20rpx 8rpx 20rpx">
        <uni-forms labelWidth="auto">
			<uni-forms-item label="车牌号:">
			  <text  >{{ isNoEmpty(ruleForm.outStorageVo.carNo) }}</text>
			</uni-forms-item>
			  <uni-forms-item label="车架号:">
				<text >{{ isNoEmpty(ruleForm.outStorageVo.vinNo)  }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="发动机号码:">
				<text >{{ isNoEmpty(ruleForm.outStorageVo.engineNo)  }}</text>
			  </uni-forms-item>

			  <uni-forms-item label="排量:">
				<text >{{ isNoEmpty(ruleForm.outStorageVo.liter)  }}</text>
			  </uni-forms-item>

			  <uni-forms-item label="环保标准:">
				<text >{{ isNoEmpty(ruleForm.outStorageVo.environmentalStandards) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="是否包含替车:">
			  				<text v-if="ruleForm.orderInfoVo.isReplacementCar==0">否</text>
			  				<text v-else>是</text>
			  </uni-forms-item>
			  <uni-forms-item label="替车时效:">
			  				<text >{{ isNoEmpty(ruleForm.orderInfoVo.replacementCarValidity) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="合同时效:">
			  				<text >{{ isNoEmpty(ruleForm.orderInfoVo.contractValidity) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="采购单价:">
			  				<text >{{ isNoEmpty(ruleForm.outStorageVo.purchasePrice) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="指导价:">
			  				<text >{{ isNoEmpty(ruleForm.outStorageVo.guidancePrice) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="每期租金:">
			  				<text >{{ isNoEmpty(ruleForm.orderInfoVo.planRent) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="租赁期（月）:">
			  				<text >{{ isNoEmpty(ruleForm.orderInfoVo.leaseTerm) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="入库里程(km):">
			  				<text >{{ isNoEmpty(ruleForm.outStorageVo.inboundMileage) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="入库油量(%)">
			  				<text >{{ isNoEmpty(ruleForm.outStorageVo.inboundOilQuantity) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="是否安装GPS:" >
			  				<text v-if="ruleForm.gpsDetailVo.isInstallation==0">否</text>
			  				<text v-else-if="ruleForm.gpsDetailVo.isInstallation==1">是</text>
			  </uni-forms-item>
			  <uni-forms-item label="GPS设备状态:" >
			  				<text >{{ isNoEmpty(ruleForm.gpsDetailVo.gpsState) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="GPS品牌:" >
			  				<text >{{ isNoEmpty(ruleForm.gpsDetailVo.gpsBrand )}}</text>
			  </uni-forms-item>
			  <uni-forms-item label="GPS设备类型:" >
			  				<text >{{ isNoEmpty(ruleForm.gpsDetailVo.gpsType) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="GPS时效:" >
			  				<text >{{ isNoEmpty(ruleForm.gpsDetailVo.gpsValidity) }}</text>
			  </uni-forms-item>
			  
			  <uni-forms-item label="订单编码:">
			  				<text >{{ isNoEmpty(ruleForm.orderInfoVo.orderNo) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="合同编码:">
			  				<text >{{ isNoEmpty(ruleForm.orderInfoVo.contractNo) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="入库编码:">
			  				<text >{{ isNoEmpty(ruleForm.outStorageVo.inboundCode) }}</text>
			  </uni-forms-item> 
        </uni-forms>
      </view>
    </view>
  </view>
</template>

<script>
	import {
	  getPurchaseQualifiedCard, carGpsInstall, getQuotaProductByOrderCar, carGpsMonitoring, carPrchaseTax, carInspection, carInsurance, carInspectionNextTime
	} from "@/api/storage/in.js";
	var moment = require('@/utils/moment.js');
export default {
  name: 'outCarInfo',//基础信息
  dicts: ['fuel_type', 'car_business_type'],
  props: {
   value: {
     type: Object,
     default: {}
   }
  },
 computed: {
   ruleForm: {
     get() {
       let that = this
       const proxy = new Proxy(that.value, {
         get(target, key) {
           return Reflect.get(target, key)
         },
         set(target, key, value) {
           that.$emit('input', {...target, [key]: value})
           return true
         }
       })
       return proxy
     }
   },
   handleLabel() {
     return function (arr, type) {
       let name = ''
       arr.map((v) => {
         if (type == v.value) {
           name = v.label;
         }
       });
       return name
     }
   }
 },
 watch:{
	'ruleForm.gpsDetailVo':{
		deep:true,
		handler(val){
			this.ruleForm.gpsDetailVo = val
		},
		immediate:true
	},
	'ruleForm.outStorageVo':{
		deep:true,
		handler(val){
			this.ruleForm.outStorageVo = val
		},
		immediate:true
	},
	'ruleForm.orderInfoVo':{
		deep:true,
		handler(val){
			this.ruleForm.orderInfoVo = val
		},
		immediate:true
	},
 },
  data() {
    return {};
  },
  mounted() {
	  this.detailInfo()
  },
  methods: {
	   getCarGpsInfo(carId){
	         if (this.Empty(carId)) return;
	         carGpsInstall(carId).then(res => {
	           var d = res.data;
	           if (!d) {
	             d = {};
	           }
	           console.log(d,'111111111')
	           this.ruleForm.gpsDetailVo.gpsType = {'1':'有线','2':'无线','3':'有线+无线'}[new String(d.equipmentType).trim()];
	           var year = d.gpsServicePeriod?.match(/\d*/)[0]
	           this.ruleForm.gpsDetailVo.installTime = d.installTime;
	           this.ruleForm.gpsDetailVo.gpsBrand = d.gpsBrand;
	           this.ruleForm.gpsDetailVo.gpsValidity =d.installTime? moment(d.installTime).add(year^0, 'years').format("YYYY-MM-DD HH:mm:ss"):'--';
	         }).finally(() => {
	           this.loading = false
	         })
	       },
	     
	       getCarGpsMonitoring(carId){
	         if (this.Empty(carId)) return;
	         carGpsMonitoring(carId).then(res => {
	           var d = res.data;
	           if (!d) {
	             d = {};
	           }
	           this.ruleForm.gpsDetailVo.gpsState = d.gpsState;
	         }).finally(() => {
	           this.loading = false
	         })
	       },
	       detailInfo(){
	         console.log(this.ruleForm,'this.ruleForm')
	         console.log('进来了')
	         var _this = this;
	         if (this.ruleForm != null && this.ruleForm.carOutStorage != null) {
	          // 用的是入库id
			  console.log(this.ruleForm.inboundId,'this.ruleForm.inboundId')
			   const param = {
				inboundId:this.ruleForm.inboundId?this.ruleForm.inboundId:'-1',
				carId:this.ruleForm.carOutStorage.carId?this.ruleForm.carOutStorage.carId:-1,
			   }
			   if(param.inboundId=='null'){
				   param.inboundId = -1
			   }
			   console.log(param)
	           this.getCarGpsInfo(param);
	           this.getCarGpsMonitoring(this.ruleForm.carOutStorage.carId);
	          
	         } else {
	         //   setTimeout(function () {
	         //     _this.detailInfo();
	         //   }, 100)
	         }
	       },
  },
};
</script>

<style lang="scss" scoped>
.car-wrap {
  display: flex;
  flex-direction: column;
  padding: 20rpx 20rpx 20rpx 0;
  border: 1px solid #dadada;
  margin: 10rpx 20rpx;
  border-radius: 8rpx;

}


</style>


